package com.hu.zhcc.shiro.controller.HealthIntervention;

import com.hu.zhcc.shiro.entity.bo.HealthIntervention.FormulateScheme;
import com.hu.zhcc.shiro.entity.dto.HealthIntervention.PopulationDTO;
import com.hu.zhcc.shiro.service.HealthIntervention.FormulateSchemeService;
import com.hu.zhcc.shiro.service.HealthIntervention.PopulationclassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("formulate")
public class FormulateSchemeController {
    @Autowired
    private FormulateSchemeService schemeService;
    @Autowired
    public PopulationclassificationService service;

    //初始查询
    @GetMapping("/{id}")
    public ResponseEntity<FormulateScheme> selectFormulate(@PathVariable("id") int id){
        FormulateScheme formulateScheme = schemeService.selectByPrimaryKey(id);
        return ResponseEntity.ok(formulateScheme);
    }

    //添加
    @PostMapping("")
    public int addFormulate(@RequestBody FormulateScheme formulateScheme){
        int i = schemeService.insertSelective(formulateScheme);
        if(i > 0) {
            service.updateByIdFormulateStart(formulateScheme.getId());
            return i;
        }
       return 0;
    }


    //根据编号进行查询并修改
    @GetMapping("selectFormulateByPopId/{id}")
    public ResponseEntity<FormulateScheme> selectFormulateByPopId(@PathVariable("id") Integer id){
        FormulateScheme scheme = schemeService.findFormulateByPopId(id);
        return ResponseEntity.ok(scheme);
    }

    //修改
    @PutMapping("")
    public int updateFormulate(@RequestBody FormulateScheme formulateScheme){
        return schemeService.updateByPrimaryKeySelective(formulateScheme);
    }
}
